import {ref,computed} from 'vue'
import { defineStore } from 'pinia'
import {getBasicsSetting} from '@/common/request/api'
import type {BasicsSetting} from '@/common/request/api'


export const useBasics = defineStore('basics',() => {
	// 基础配置项，包含用户协议列表与注册配置项
	const basicsSetting = ref<BasicsSetting>({
		agreements:[],
		customerInfos:[],
		registerModel:'',
		registerType:''
	})
	const agreement = computed(() => basicsSetting.value.agreements)
	const hasInvitation = computed(() => (basicsSetting.value.registerType?.split(',')||[]).includes('salt'))
	const registerModel = computed(() => basicsSetting.value.registerModel?.split(',')||[])
	
	const _getBasicsSetting = async () => {
		const res = await getBasicsSetting()
		basicsSetting.value = res.data
		return res.data
	}
	
	return {
		basicsSetting,
		agreement,
		hasInvitation,
		registerModel,
		getBasicsSetting:_getBasicsSetting
	}
})